package com.ryan.demo.grpc.server.service;

import com.ryan.demo.grpc.api.AckReceiptData;
import com.ryan.demo.grpc.api.ReceiveEventData;
import com.ryan.demo.grpc.api.SubEventHubGrpc;
import io.grpc.Deadline;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @description： SpecifyPubService
 * @Author MRyan
 * @Date 2023/10/7 17:43
 * @Version 1.0
 */

@Service
public class SpecifyPubService {

    @Resource(name = "subEventHubBlockingStub")
    private SubEventHubGrpc.SubEventHubBlockingStub subEventHubBlockingStub;

    public AckReceiptData receiveEvent() {
        ReceiveEventData receiveEventData = ReceiveEventData.newBuilder()
                .setDomain("D")
                .setScene("S")
                .setCommand("C")
                .setMetaData("M")
                .build();
        return subEventHubBlockingStub
                .withDeadline(Deadline.after(20, TimeUnit.SECONDS))
                .receiveEvent(receiveEventData);
    }

}
